﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfPathExample
{
    /// <summary>
    /// PageRectangleWithArrow.xaml 的交互逻辑
    /// </summary>
    public partial class PageRectangleWithArrow : Page
    {
        public PageRectangleWithArrow()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(PageRectangleWithArrow_Loaded);
        }

        void PageRectangleWithArrow_Loaded(object sender, RoutedEventArgs e)
        {
            //pathTest.Data = Create(400, 200, 300);

            DrawingBrush brush = new DrawingBrush();
            //brush.Drawing 
            GeometryDrawing drawing = new GeometryDrawing(Brushes.LightGreen, new Pen(Brushes.LightGray, 1), Create(400, 200, 100));
            brush.Drawing = drawing;
           // border1.Background = brush;
        }

        StreamGeometry Create(double width, double height, double arrow)
        {
            StreamGeometry geometry = new StreamGeometry();
            geometry.FillRule = FillRule.Nonzero;
            using (StreamGeometryContext context = geometry.Open())
            {
                context.BeginFigure(new Point(10, 0), true, true);
                //right top
                context.LineTo(new Point(width - 10, 0), true, false);
                //first point ,end point ,control point
                context.BezierTo(new Point(width - 5, 0), new Point(width, 5), new Point(width, 10), true, false);

                //right down
                context.LineTo(new Point(width, height - 30), true, false);
                context.BezierTo(new Point(width, height - 25), new Point(width - 5, height - 20), new Point(width - 10, height - 20), true, false);

                context.LineTo(new Point(arrow + 20, height - 20), true, false);
                context.LineTo(new Point(arrow, height), true, false);
                context.LineTo(new Point(arrow - 20, height - 20), true, false);
                context.LineTo(new Point(10, height - 20), true, false);


                //left down
                //context.LineTo(new Point(10, height-20), true, false);
                context.BezierTo(new Point(5, height - 20), new Point(0, height - 25), new Point(0, height - 30), true, false);


                //left top
                context.LineTo(new Point(0, 10), true, false);
                context.BezierTo(new Point(0, 5), new Point(5, 0), new Point(10, 0), true, false);
            }
            return geometry;
        }
    }
}
